import React from 'react';

import Constants from '../../common/Constants';
import BaseAction from '../common/BaseAction';

export default class JianYiRequestOwnedAction extends BaseAction {
	constructor() {
		super();

		this.moduleType = Constants.MODULE_TYPE.JIANYI;
		this.name = 'JianYiRequestOwnedAction';
	}

	finish(data, isSucceed, response) {
		/**
		 * { Suggests: 
   [ { Suggest_id: '5aa71cc75613cfc1ccc5e068',
       comment: '',
       create_at: '2018-03-13 08:35:19.354 +0800 CST',
       is_comment: 0,
       title: '对App的建议或意见,对App的建议或意见',
       type: 1,
       uid: '5a90fd805613cfc1ccb32a7a',
       update_at: '2018-03-13 08:35:19.354 +0800 CST' } ],
  page: 1,
  total_page: 1 }
		 */
		if (isSucceed) {
			let dic = {
				viewStatus: 3,
				isResponeUpdate: true
			};
			let dataKey = this.data.dataKey || 'data';
			dic[dataKey] = data.Suggests;
			
			this.caller.setState(dic);
		} else if (data) {
			if (data.status == 401) {
				this._dealUnauthorized(this.caller);
			} else {
				this.caller.setState({ viewStatus: data.status });
			}
		} else {
			this.caller.setState({ viewStatus: 400 });
		}
	}
}
